from .asyn import AsynTask    
import urllib.request as ur

class HTTP(AsynTask):
    """
        a simple for get some thing from http
        just implement GET
    """
    def do(self,url):
        try:
            response = ur.urlopen(url)
        except Exception  as e:
            print(e)
        except Future.exception(timeout=self.timeout):
            print("time out :",self.timeout)
        finally:
            return response.read()

    def callback(self,future):
        """
        this is a sample
        """
        result = future.result()
        if future in  HTTP.temp_future:
            arg = HTTP.temp_future[future]
        with open(arg[-1]+".log","w") as fp:
            print(result,file=fp)

    def Get(self,url,callback):
        """
        
        """
        self.do_background(url,callback=callback)

    def Post(self,url,callable):
        pass
